using System;
using System.Collections.Generic;

namespace GameFramework.Extensions
{
    /// <summary>
    /// List extensions methods.
    /// </summary>
    public static class ListExtensions
    {
        /// <summary>
        /// Remove all the items in a list that satisfy a specific predicate.
        /// </summary>
        /// <param name="items">The list of items.</param>
        /// <param name="predicate">The predicate.</param>
        /// <typeparam name="T">The type of the elements.</typeparam>
        public static void RemoveAll<T>(this IList<T> items, Func<T, bool> predicate)
        {
            for (int i = items.Count - 1; i >= 0; --i)
            {
                if (predicate(items[i]))
                {
                    items.RemoveAt(i);
                }
            }
        }
    }
}
